from django.shortcuts import render
from rest_framework.views import APIView
from rest_framework.response import Response
from .ser import *
from .models import *


# Create your views here.


class KeeperM(APIView):
    def post(self, request):
        name = request.data.get('username')
        password = request.data.get('password')
        gain = Keeper.objects.filter(username=name).first()
        if gain:
            if gain.password == password:
                return Response({'code': 200, 'userid': gain.id})
            else:
                return Response({'code': 10010})
        else:
            return Response({'code': 10012})

    def get(self,request):
        gain = Keeper.objects.all()
        ser = KeeperSer(gain, many=True)
        return Response({'code': 200, 'matter': ser.data})


class GoodsM(APIView):
    def get(self, request):
        gain = Goods.objects.all()
        ser = GoodsSer(gain, many=True)
        return Response({'code': 200, 'matter': ser.data})